package com.wtwd.campus.controller;

import com.wtwd.campus.common.RespCode;
import com.wtwd.campus.common.RespEntity;
import com.wtwd.campus.entity.AttendanceRecordVO;
import com.wtwd.campus.entity.ExportAttendanceRecord;
import com.wtwd.campus.service.AttendanceRulesService;
import com.wtwd.campus.utils.MyExcelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @Author px
 * @Date 2021年12月14日 13:39:01
 * @Description 考勤记录
 */
@RestController
@RequestMapping("/attendanceRecord")
public class AttendanceRecordController {

    private static final Logger logger = LoggerFactory.getLogger(AttendanceRecordController.class);

    @Autowired
    private AttendanceRulesService attendanceRulesService;

    /**
     * 条件查询考勤记录
     *
     * @param data
     * @return
     */
    @PostMapping("/getAttendanceRecordList")
    public RespEntity getAttendanceRecordList(@RequestBody AttendanceRecordVO data) {
        logger.info("/getAttendanceRecordList,data={}", data.toString());
        //条件查询考勤记录
        Map<String, Object> recordList = attendanceRulesService.getAttendanceRecordList(data);
        return new RespEntity(RespCode.SUCCESS,recordList);
    }

    /**
     * 条件导出考勤记录
     *
     * @param data
     * @return
     */
    @PostMapping("/exportAttendanceRecordList")
    public RespEntity exportAttendanceRecordList(@RequestBody AttendanceRecordVO data, HttpServletResponse response) {
        logger.info("/exportAttendanceRecordList,data={}", data.toString());
        //条件查询考勤记录
        List<ExportAttendanceRecord> exportRecordList = attendanceRulesService.getExportRecordList(data);
        String path = MyExcelUtils.exportExcel(exportRecordList, "学生考勤信息", "学生考勤信息", ExportAttendanceRecord.class, "学生考勤信息.xls", response);
        return new RespEntity(RespCode.SUCCESS,path);
    }
}
